<?php

namespace App\Console\Commands;

use App\AdminRecord;
use Illuminate\Console\Command;
use function GuzzleHttp\Psr7\uri_for;

class AdminRecord2Command extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'admin:record1 {name}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $name=$this->argument('name');
        AdminRecord::where('types','crm_customer')->where('content','like','%'.$name.'%')
            ->chunkById(100,function ($records){
                foreach ($records as $record){
                    /**
                     * @var AdminRecord $record
                     */
                $customer= \App\Customer::where('customer_id',$record->types_id)->first();
                if ($customer){
                    $customer->remark=$customer->remark.','.$record->content;
                    $customer->save();
                    $this->info($customer->customer_id);
                }
                }
            });
    }
}
